
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifndef NULL
#define NULL 0
#endif
#ifndef delay_queue
#define delay_queue
#endif
#ifdef delay_queue
typedef void (*callback)(void * client_data);

typedef struct delay_entry
{
	struct delay_entry *prev,*next;
	callback delay_handler;
	void *client_data;
	unsigned int seconds_to_delay;
	time_t last_time;
}delay_entry_t;

typedef struct delay_queue
{
	delay_entry_t *first_entry,*last_entry;
}delay_queue_t;

void add_entry(delay_queue_t *delay_queue0,delay_entry_t *delay_entry0);

void del_entry(delay_queue_t *delay_queue0,delay_entry_t *delay_entry0);

delay_queue_t * delay_queue_init();

void delay_queue_destory(delay_queue_t *delay_queue0);

void delay_queue_reset(delay_queue_t *delay_queue0);

void call_later(int seconds_to_delay,callback f_handler,void *client_data,delay_queue_t *delay_queue0);//client_data must malloc before call this function

int time_synchronize(delay_queue_t *delay_queue0);

#endif
